export function getNowTime() {
  let now = new Date()

  let year = now.getFullYear() //年
  let month = now.getMonth() + 1 //月
  let day = now.getDate() //日

  let hh = now.getHours() //时
  let mm = now.getMinutes() //分
  let ss = now.getSeconds() //秒

  let clock = year

  if (month < 10) clock += '0'

  clock += month

  if (day < 10) clock += '0'

  clock += day

  if (hh < 10) clock += '0'

  clock += hh
  if (mm < 10) clock += '0'
  clock += mm

  if (ss < 10) clock += '0'
  clock += ss
  return clock
}
export function getNowTime2() {
  let now = new Date()

  let year = now.getFullYear() //年
  let month = now.getMonth() + 1 //月
  let day = now.getDate() //日

  let hh = now.getHours() //时
  let mm = now.getMinutes() //分
  let ss = now.getSeconds() //秒

  let clock = year + '-'

  if (month < 10) clock += '0'

  clock += month + '-'

  if (day < 10) clock += '0'

  clock += day + ' '

  if (hh < 10) clock += '0'

  clock += hh + ':'
  if (mm < 10) clock += '0'
  clock += mm + ':'

  if (ss < 10) clock += '0'
  clock += ss
  return clock
}

export function fmtDate(date) {
  var y = 1900 + date.getYear()
  var m = '0' + (date.getMonth() + 1)
  var d = '0' + date.getDate()
  var h = '0' + date.getHours()
  var min = '0' + date.getMinutes()
  var s = '0' + date.getSeconds()
  return (
    y +
    '-' +
    m.substring(m.length - 2, m.length) +
    '-' +
    d.substring(d.length - 2, d.length) +
    ' ' +
    h.substring(h.length - 2, h.length) +
    ':' +
    min.substring(min.length - 2, min.length) +
    ':' +
    s.substring(s.length - 2, s.length)
  )
}

/**
 * 毫米数转换 yyyy-MM-dd hh:mm:ss
 * @param date
 * @returns {string}
 */
export function fmtDate2(timestamp) {
  let date = new Date(timestamp)
  var y = 1900 + date.getYear()
  var m = '0' + (date.getMonth() + 1)
  var d = '0' + date.getDate()
  var h = '0' + date.getHours()
  var min = '0' + date.getMinutes()
  var s = '0' + date.getSeconds()
  return (
    y +
    '-' +
    m.substring(m.length - 2, m.length) +
    '-' +
    d.substring(d.length - 2, d.length) +
    ' ' +
    h.substring(h.length - 2, h.length) +
    ':' +
    min.substring(min.length - 2, min.length) +
    ':' +
    s.substring(s.length - 2, s.length)
  )
}

export function getWeek(dateStr) {
  let date = new Date(dateStr)
  let week
  if (date.getDay() == 0) week = '周日'
  if (date.getDay() == 1) week = '周一'
  if (date.getDay() == 2) week = '周二'
  if (date.getDay() == 3) week = '周三'
  if (date.getDay() == 4) week = '周四'
  if (date.getDay() == 5) week = '周五'
  if (date.getDay() == 6) week = '周六'
  return week
}
